package net.dasoft.controller;

import net.dasoft.entity.Account;
import net.dasoft.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/account/findAll")
    public String findAll(Model model, HttpServletResponse response){
        System.out.println("Controller表现层：查询所有用户..");
        List<Account> list = accountService.FindAll();
        model.addAttribute("list",list);
        return "list";
    }


    @RequestMapping("/account/save")
    public void save(Account account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("Controller表现层：保存所有用户..");
        accountService.saveAccount(account);
        response.sendRedirect(request.getContextPath() + "/account/findAll");
        return;
    }

    @RequestMapping("/index")
    public String index(Model model, HttpServletResponse response){
        return "index";
    }
}
